<template>
  <div>
    <el-row type="flex" justify="end">
      <el-button
        style="background: #316edc; color: white"
        @click="dialogFormVisible = true"
        >新增模板</el-button
      >
      <el-button
        style="background: #ebf0fc; color: #799de2; border: 1px solid #6d89b3"
        @click="inform"
        >消息通知</el-button
      >
    </el-row>

    <!-- 表格 --><!-- 数据 -->
    <div style="border: 1px solid #f0f0f2; margin-top: 10px">
      <!-- 表格 -->
      <el-table
        :data="tableData"
        :row-class-name="tableRowClassName"
        style="width: 100%"
        :header-cell-style="{ background: '#eef2f5' }"
      >
        <el-table-column
          type="index"
          label="模板ID"
          width="100"
          align="center"
        />
        <el-table-column
          prop="name"
          label="模板类型"
          width="150"
          align="center"
        />
        <el-table-column prop="date" label="模板内容" align="left" />
        <el-table-column
          prop="date"
          label="更新时间"
          width="200"
          align="center"
        />
        <el-table-column prop="date" label="操作" width="173" align="center">
          <el-button type="text">查看</el-button>
          <el-button type="text">修改</el-button>
          <el-button type="text">删除</el-button>
        </el-table-column>
      </el-table>
    </div>

    <!-- 模态框 -->
    <el-dialog
      title="新增模板"
      :visible.sync="dialogFormVisible"
      @clone="cancel"
      width="30%"
    >
      <el-form :model="form" label-width="100px">
        <el-form-item label="模板名称：">
          <el-input v-model="form.name" autocomplete="off" />
        </el-form-item>
        <el-form-item label="模板内容：">
          <el-input type="textarea" v-model="form.name" resize="none" />
        </el-form-item>
        <el-form-item label="模板ID：">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-row type="flex" justify="center">
          <el-col :span="8">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="btnOK">保存</el-button>
          </el-col>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    flag: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
      ],
      dialogFormVisible: false,
      form: {},
    };
  },
  methods: {
    // 取消
    cancel() {},
    // 确认
    btnOK() {},
    // 表格自定义样式
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 !== 0) {
        return "gray-row";
      }
      return "";
    },
    inform() {
      this.$emit("update:flag", true);
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-table .gray-row {
  background: #eef1f7;
}
::v-deep .el-dialog__header {
  border-bottom: 1px solid gray;
}
</style>
